package com.itkaien.javaeebased;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Random;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Role {

    //名称
    private String roleName;
    //血量
    private Integer blood;

    //攻击方法
    public void attack(Role role){
        //伤害随机
        Random arm=new Random();
        int finalarm= arm.nextInt(20)+1;
        //this标识当前调用者，
        //role标识被调用者
        Integer finalroleBloodDesc = role.getBlood()-finalarm;
        Integer finalroleBloodDescfinal=finalroleBloodDesc<0?0:finalroleBloodDesc;
        role.setBlood(finalroleBloodDescfinal);
        System.out.println(this.roleName+"攻击了"+role.roleName);
        System.out.println(role.roleName+"剩余血量"+role.getBlood());
    }

}
